package cn.itrigger.dynamic.sql.render;

import cn.itrigger.dynamic.sql.structure.SqlTable;

import java.util.Map;
import java.util.Optional;

/**
 * @author admin
 * @date 2018/9/25
 **/
public class GuaranteedTableAliasCalculator extends TableAliasCalculator {

    private GuaranteedTableAliasCalculator(Map<SqlTable, String> aliases) {
        super(aliases);
    }

    @Override
    public Optional<String> alias(SqlTable sqlTable) {
        return super.alias(sqlTable)
                .map(Optional::of)
                .orElse(Optional.of(sqlTable.name()));
    }

    public static TableAliasCalculator of(Map<SqlTable, String> aliases) {
        return new GuaranteedTableAliasCalculator(aliases);
    }
}
